package org.study.user.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.study.user.model.User;

@Repository
public class UserDao {
	@Autowired
	protected JdbcTemplate jdbcTemplate;
	
	public User getUserById(long id) {
		return jdbcTemplate.queryForObject("select * from user where id=?", new Object[] {id},new BeanPropertyRowMapper<>(User.class));
	}

	public boolean findUser(User user) {
		return jdbcTemplate.queryForObject("select count(1) from user where user_name=? and password=?",new Object[]{user.getUser_name(),user.getPassword()},
				Integer.class)>0;
	}
}
